<template>
  <div>
    <h1>展示未绑定学生</h1>
    <table>
      <tr>
        <td>学生姓名</td>
        <td>学生年龄</td>
        <td>操作</td>
      </tr>
      <tr v-for="i in stulist">
        <td>{{ i.name }}</td>
        <td>{{ i.age }}</td>
        <td>
          <button @click="bind(i.id)">绑定</button>
        </td>
      </tr>
    </table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      stulist: []
    }
  },
  methods: {
    getStulist() {
      this.axios.get('stuM/')
        .then(res => {
          this.stulist = res.data.list
        })
    },
    bind(id) {
      let tid = localStorage.getItem('tid')
      this.axios.put('stuM/', {'tid': tid, 'sid': id})
        .then(res => {
          this.stulist = res.data.list
        })
    }
  },
  mounted() {
    this.getStulist()
  }
}
</script>

<style scoped>

</style>
